package com.example.rental.service.impl;

import com.example.rental.entity.Houseinfo;
import com.example.rental.entity.Oder;
import com.example.rental.entity.dto.HouseDto;
import com.example.rental.mapper.HouseMapper;
import com.example.rental.result.Result;
import com.example.rental.service.HouseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Data
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseMapper houseMapper;

    @Override
    public Result list(HouseDto houseDto) {
        PageHelper.startPage(houseDto.getPage(), houseDto.getLimit());

        List<Houseinfo> list = houseMapper.list(houseDto);

        Page page = (Page) list;
        Result<Page> result = Result.ok(page);
        result.setCount(page.getTotal());

        return result;
    }
    @Override
    public void addHouse(Houseinfo house){houseMapper.addHouse(house);};
    @Override
    public void updateHouse(Houseinfo house){houseMapper.updateHouse(house);};
    @Override
    public void deleteHouseid(Houseinfo house){houseMapper.deleteHouseid(house);};
    @Override
    public List<Integer> searchHouseByHouseid(Integer houseid) { return houseMapper.searchHouseByHouseid(houseid);}
    @Override
    public void updateHouseByHouseid(Integer houseid){houseMapper.updateHouseByHouseid(houseid);}
    @Override
    public void updateAllHouse(Oder oder){houseMapper.updateAllHouse(oder);};
}
